<?php

/**
 * 
 *
 * @version $Id: class_upload.inc.php,v 1.5 2005/01/03 13:41:29 phppc Exp $
 * @copyright 2004 
 **/

/**
 * upload
 * 
 * @package 
 * @author Armin
 * @copyright Copyright (c) 2004
 * @version $Id: class_upload.inc.php,v 1.5 2005/01/03 13:41:29 phppc Exp $
 * @access public
 **/
class upload extends uf{
	/**
	 * upload::upload_check()
	 * 
	 * @param $form_var
	 * @param $endungen
	 * @param $max_size
	 * @return 
	 **/
	function upload_check($form_var,$endungen,$max_size) {
		$file_types_pattern = str_replace(" ","|",$endungen);
		$file_pattern = "!([a-z_0-9_]+)(.{1})($file_types_pattern){1}!i";
		if(($_FILES["$form_var"]["size"] <= $max_size) AND (preg_match($file_pattern,$_FILES["$form_var"]["name"]))) $valid_file = 1;
		else $valid_file = 0;
		return $valid_file;
	}
	/**
	 * upload::upload_do()
	 * 
	 * @param $form_var
	 * @param $endungen
	 * @param $max_size
	 * @param $dir
	 * @param string $new_name
	 * @return 
	 **/
	function upload_do ($form_var,$endungen,$max_size,$dir,$new_name="") {
		if ($this->upload_check($form_var,$endungen,$max_size) == 1) {
			$filename_array = explode(".",$_FILES["$form_var"]["name"]);
			$endung = $filename_array[1];
			if($new_name == "") $upload_name = $_FILES["$form_var"]["name"];
			else $upload_name = $new_name .".$endung";
			if (move_uploaded_file($_FILES["$form_var"]["tmp_name"], $dir . $upload_name)) $valid_upload = 2;
			else $valid_upload = 1;
		}else $vaild_upload = 0;
		return $valid_upload;
	}
}

?>